package com.mmz.test.socket;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Writer;
import java.net.InetAddress;
import java.net.Socket;

public class Client {
	
	public static void main(String[] args) {
		
		try {
			// 输出到服务端
			Socket socket = new Socket("localhost", 8080);
			OutputStream os = socket.getOutputStream();
			os.write("hello.socket on TCP".getBytes());
			os.flush();
			socket.shutdownOutput();
			// 读取到服务端的输出
			InputStream is = socket.getInputStream();
			InputStreamReader reader = new InputStreamReader(is);
			BufferedReader br = new BufferedReader(reader);
			String info =null;
			while((info=br.readLine())!=null){
				System.out.println(info);
			}
			socket.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
